package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.SchCourseStudent;
import com.ruoyi.teach.service.ISchCourseStudentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程关联学生Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@RestController
@RequestMapping("/teach/course_student")
public class SchCourseStudentController extends BaseController
{
    @Autowired
    private ISchCourseStudentService schCourseStudentService;

    /**
     * 查询课程关联学生列表
     */
    @PreAuthorize("@ss.hasPermi('teach:course_student:list')")
    @GetMapping("/list")
    public TableDataInfo list(SchCourseStudent schCourseStudent)
    {
        startPage();
        List<SchCourseStudent> list = schCourseStudentService.selectSchCourseStudentList(schCourseStudent);
        return getDataTable(list);
    }

    /**
     * 导出课程关联学生列表
     */
    @PreAuthorize("@ss.hasPermi('teach:course_student:export')")
    @Log(title = "课程关联学生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchCourseStudent schCourseStudent)
    {
        List<SchCourseStudent> list = schCourseStudentService.selectSchCourseStudentList(schCourseStudent);
        ExcelUtil<SchCourseStudent> util = new ExcelUtil<SchCourseStudent>(SchCourseStudent.class);
        util.exportExcel(response, list, "课程关联学生数据");
    }

    /**
     * 获取课程关联学生详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:course_student:query')")
    @GetMapping(value = "/{stId}")
    public AjaxResult getInfo(@PathVariable("stId") Long stId)
    {
        return AjaxResult.success(schCourseStudentService.selectSchCourseStudentByStId(stId));
    }

    /**
     * 新增课程关联学生
     */
    @PreAuthorize("@ss.hasPermi('teach:course_student:add')")
    @Log(title = "课程关联学生", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchCourseStudent schCourseStudent)
    {
        return toAjax(schCourseStudentService.insertSchCourseStudent(schCourseStudent));
    }

    /**
     * 修改课程关联学生
     */
    @PreAuthorize("@ss.hasPermi('teach:course_student:edit')")
    @Log(title = "课程关联学生", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchCourseStudent schCourseStudent)
    {
        return toAjax(schCourseStudentService.updateSchCourseStudent(schCourseStudent));
    }

    /**
     * 删除课程关联学生
     */
    @PreAuthorize("@ss.hasPermi('teach:course_student:remove')")
    @Log(title = "课程关联学生", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stIds}")
    public AjaxResult remove(@PathVariable Long[] stIds)
    {
        return toAjax(schCourseStudentService.deleteSchCourseStudentByStIds(stIds));
    }
}
